/**
 * Copyright (C) 2011-2012 Luca Li Greci
 *
 * This file is part of pojo-creator
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.pojocreator.provider.string;

import org.apache.commons.lang.RandomStringUtils;

import com.pojocreator.provider.DataProvider;

/**
 * This class implements {@link DataProvider} to provide a random alphabetic string.
 * <p>
 * The string length is 10 chars by default, otherwise you can specify the 
 * max number of characters using the constructor {@link RandomAlphabetic#RandomAlphabetic(int)}.
 * 
 * @author Luca Li Greci
 */
public class RandomAlphabetic implements DataProvider < String > {
    private static final int NUMBER_OF_LETTERS = 10;
    private int maxChars;
    
    /**
     * Creates an instance of RandomAlphabeticDataProvicer with a random string 
     * whose length is 10 characters.
     */
    public RandomAlphabetic() {
        this(NUMBER_OF_LETTERS);
    }
    
    /**
     * Creates a random string whose length is max number of characters
     * specified.
     * 
     * @param maxChars Max number of char
     */
    public RandomAlphabetic(int maxChars) {
        this.maxChars = maxChars;
    }

    @Override
    public String data() {
        return RandomStringUtils.randomAlphabetic(maxChars);
    }

    /**
     * Return the type of element managed.
     * 
     * @return The type of element managed is <code>String.class</code> 
     */
    @Override
    public Class < String > type() {
        return String.class;
    }
    
    /**
     * The number of elements returned is 1
     * 
     * @return number of elements returned is 1
     */
    @Override
    public int size() {
        return 1;
    }

}
